package com.example.pinkcat;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.pinkcat.activity.pinkCatUser.Save_set_Msg;
import com.example.pinkcat.activity.pinkCatUser.userStaticMsg;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;


import com.example.pinkcat.activity.api.getData.GetData;

import java.util.Objects;
/*sadafwiafnanfaiuhf啊士大夫*/
public class MainActivity extends AppCompatActivity{
    Context context=this;

    /*
    bm_title
    bm_back
    bottom_title_bar
   首页 动态 投稿 我的
 */

    private RelativeLayout main_body;
    private TextView bottom_bar_text_1;
    private ImageView bottom_bar_image_1;
    private TextView bottom_bar_text_2;
    private ImageView bottom_bar_image_2;
    private TextView bottom_bar_text_3;
    private ImageView bottom_bar_image_3;
    private TextView bottom_bar_text_4;
    private ImageView bottom_bar_image_4;

    private LinearLayout main_body_bar;
    private RelativeLayout bottom_bar_1_btn;
    private RelativeLayout bottom_bar_2_btn;
    private RelativeLayout bottom_bar_3_btn;
    private RelativeLayout bottom_bar_4_btn;




    NavController navController;


    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        Objects.requireNonNull(getSupportActionBar()).hide();//去掉标题栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        setContentView(R.layout.activity_main);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }//深色信息栏
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);//允许此线程内发起网络请求


        Save_set_Msg.setMsg(context);
        GetData.longin(userStaticMsg.phone,userStaticMsg.mail,userStaticMsg.password,context,false);
        initViews();
        navController = Navigation.findNavController(findViewById(R.id.fl_container));
    }


    private void initViews() {



        bottom_bar_text_1 = findViewById(R.id.bottom_bar_text_1);
        bottom_bar_text_2 = findViewById(R.id.bottom_bar_text_2);
        bottom_bar_text_3 = findViewById(R.id.bottom_bar_text_3);
        bottom_bar_text_4 = findViewById(R.id.bottom_bar_text_4);

        bottom_bar_image_1 = findViewById(R.id.bottom_bar_image_1);
        bottom_bar_image_2 = findViewById(R.id.bottom_bar_image_2);
        bottom_bar_image_3 = findViewById(R.id.bottom_bar_image_3);
        bottom_bar_image_4 = findViewById(R.id.bottom_bar_image_4);


        bottom_bar_1_btn = findViewById(R.id.bottom_bar_1_btn);
        bottom_bar_2_btn = findViewById(R.id.bottom_bar_2_btn);
        bottom_bar_3_btn = findViewById(R.id.bottom_bar_3_btn);
        bottom_bar_4_btn = findViewById(R.id.bottom_bar_4_btn);

        bottom_bar_1_btn.setSelected(true);
        bottom_bar_text_1.setTextColor(getResources().getColor(R.color.pink));

        bottom_bar_1_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                navController.navigate(R.id.nav_shouye);
                bottom_bar_1_btn.setSelected(true);
                bottom_bar_2_btn.setSelected(false);
                bottom_bar_3_btn.setSelected(false);
                bottom_bar_4_btn.setSelected(false);
                setSelectStatus(0);
            }
        });
        bottom_bar_2_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!userStaticMsg.userId.equals("-1")){
                navController.navigate(R.id.nav_dongtai);
                bottom_bar_1_btn.setSelected(false);
                bottom_bar_2_btn.setSelected(true);
                bottom_bar_3_btn.setSelected(false);
                bottom_bar_4_btn.setSelected(false);
                setSelectStatus(1);}
                else {
                    Toast.makeText(context,"请登录",Toast.LENGTH_SHORT).show();
                    navController.navigate(R.id.nav_wode);
                    bottom_bar_1_btn.setSelected(false);
                    bottom_bar_2_btn.setSelected(false);
                    bottom_bar_3_btn.setSelected(false);
                    bottom_bar_4_btn.setSelected(true);
                    setSelectStatus(3);
                }
            }
        });
        bottom_bar_3_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!userStaticMsg.userId.equals("-1")){
                navController.navigate(R.id.nav_tougao);
                bottom_bar_1_btn.setSelected(false);
                bottom_bar_2_btn.setSelected(false);
                bottom_bar_3_btn.setSelected(true);
                bottom_bar_4_btn.setSelected(false);
                setSelectStatus(2);}else {
                    Toast.makeText(context,"请登录",Toast.LENGTH_SHORT).show();
                    navController.navigate(R.id.nav_wode);
                    bottom_bar_1_btn.setSelected(false);
                    bottom_bar_2_btn.setSelected(false);
                    bottom_bar_3_btn.setSelected(false);
                    bottom_bar_4_btn.setSelected(true);
                    setSelectStatus(3);
                }
            }
        });
        bottom_bar_4_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                navController.navigate(R.id.nav_wode);
                bottom_bar_1_btn.setSelected(false);
                bottom_bar_2_btn.setSelected(false);
                bottom_bar_3_btn.setSelected(false);
                bottom_bar_4_btn.setSelected(true);
                setSelectStatus(3);
            }
        });



    }

    public void setSelectStatus(int index){
        switch (index){
            case 0:
                //图片点击选择改变图片，颜色改变，其他颜色变为原来的颜色，并保持原有的图片

                bottom_bar_text_1.setTextColor(getResources().getColor(R.color.pink));

                //其他文本和颜色不变

                bottom_bar_text_2.setTextColor(getResources().getColor(R.color.black_overlay));


                bottom_bar_text_3.setTextColor(getResources().getColor(R.color.black_overlay));

                bottom_bar_text_4.setTextColor(getResources().getColor(R.color.black_overlay));
                break;
            case 1:

                bottom_bar_text_1.setTextColor(getResources().getColor(R.color.black_overlay));

                //其他文本和颜色不变

                bottom_bar_text_2.setTextColor(getResources().getColor(R.color.pink));


                bottom_bar_text_3.setTextColor(getResources().getColor(R.color.black_overlay));


                bottom_bar_text_4.setTextColor(getResources().getColor(R.color.black_overlay));

                break;
            case 2:

                bottom_bar_text_1.setTextColor(getResources().getColor(R.color.black_overlay));

                //其他文本和颜色不变

                bottom_bar_text_2.setTextColor(getResources().getColor(R.color.black_overlay));


                bottom_bar_text_3.setTextColor(getResources().getColor(R.color.pink));


                bottom_bar_text_4.setTextColor(getResources().getColor(R.color.black_overlay));
                break;
            case 3:

                bottom_bar_text_1.setTextColor(getResources().getColor(R.color.black_overlay));

                //其他文本和颜色不变

                bottom_bar_text_2.setTextColor(getResources().getColor(R.color.black_overlay));


                bottom_bar_text_3.setTextColor(getResources().getColor(R.color.black_overlay));


                bottom_bar_text_4.setTextColor(getResources().getColor(R.color.pink));
                break;

        }
    }
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
}

